package com.skyworthclub.competition.beans;

import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableLogic;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.annotations.Version;
import com.baomidou.mybatisplus.enums.IdType;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.time.LocalDate;

/**
 * <p>
 * 
 * </p>
 *
 * @author li
 * @since 2018-10-15
 * es文档索引注解 @Document
 */
@Document(indexName = "skyworthclub-competition", type = "match", shards = 1, replicas = 0, refreshInterval = "-1")
@TableName("tbl_match")
@Data
@EqualsAndHashCode(callSuper = true)
@AllArgsConstructor
@NoArgsConstructor
public class Match extends Model<Match> {

    private static final long serialVersionUID = 1L;

    @Id
    @TableId(value = "match_id", type = IdType.AUTO)
    private Integer matchId;
    @NotEmpty
    private String matchName;
    /**
     * 发布比赛信息的用户名
     */
    @NotEmpty
    private String matchPublisher;
    private String matchImageUrl;
    @NotEmpty
    private String matchSummary;
    @NotEmpty
    private String matchDetail;

    private String matchOrganizer;
    /**
     * 协办或赞助商
     */
    private String matchCoorganizer;
    /**
     * 参赛对象
     */
    private String matchContestants;

    /** 划重点!!!
     * 这三个注解用于Elasticsearch序列化和反序列化java8 LocalDate时间类型
     */
    @JsonSerialize(using = LocalDateSerializer.class)
    @JsonDeserialize(using = LocalDateDeserializer.class)
    @JsonFormat(pattern = "yyyy-MM-dd")

    @NotNull
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private LocalDate matchSignupBegin;

    //这三个注解用于Elasticsearch序列化和反序列化java8 LocalDate时间类型
    @JsonSerialize(using = LocalDateSerializer.class)
    @JsonDeserialize(using = LocalDateDeserializer.class)
    @JsonFormat(pattern = "yyyy-MM-dd")

    @NotNull
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private LocalDate matchSignupEnd;

    //这三个注解用于Elasticsearch序列化和反序列化java8 LocalDate时间类型
    @JsonSerialize(using = LocalDateSerializer.class)
    @JsonDeserialize(using = LocalDateDeserializer.class)
    @JsonFormat(pattern = "yyyy-MM-dd")

    @NotNull
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private LocalDate matchBeginTime;

    //这三个注解用于Elasticsearch序列化和反序列化java8 LocalDate时间类型
    @JsonSerialize(using = LocalDateSerializer.class)
    @JsonDeserialize(using = LocalDateDeserializer.class)
    @JsonFormat(pattern = "yyyy-MM-dd")

    @NotNull
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private LocalDate matchEndTime;
    private String matchLocation;
    /**
     * 报名链接
     */
    @NotEmpty
    private String matchSignupUrl;

    //这三个注解用于Elasticsearch序列化和反序列化java8 LocalDate时间类型
    @JsonSerialize(using = LocalDateSerializer.class)
    @JsonDeserialize(using = LocalDateDeserializer.class)
    @JsonFormat(pattern = "yyyy-MM-dd")

    private LocalDate lastModify;

    /**
     * 审核状态:1已审核通过 0未审核 -1审核未通过
     */
    private Short isChecked;

    /**
     * 乐观锁
     */
    @Version
    private Integer version;

    /**
     * 逻辑删除字段
     */
    @TableLogic
    private Integer logicFlag;


    @Override
    protected Serializable pkVal() {
        return this.matchId;
    }

    /**
     * 比赛类型：0比赛 1考证
     */
    @NotNull
    private Integer matchType;

    /**
     * 比赛等级:0国家级 1省级 2校级 3学院级
     */
    @NotNull
    private Integer matchLevel;

    private String country;

    private String province;

    private String university;

    private String college;

}
